<?php
/**
 * Moduleadmin_Data_Updatemodule
 * update current module
 * 
 * @author Adrian Stolarski
 */
class Moduleadmin_Data_Updatemodule implements Moduleadmin_Data_Mainable, 
        Moduleadmin_Data_Preparable, Moduleadmin_Data_Redirectable{
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query
     * database query handler
     */
    public $database_query;
    /**
     *
     * @var type $redirect_action
     * redirect action
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * update module data
     * @param array $variables
     */
    public function main(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        //var_dump($variables);
        //die();
        $this->prepare_query($variables);
        //echo $this->database_query;
        //die();
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    
    /**
     * prepare_query()
     * prepare module udpate query
     * 
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        //var_dump($variables);
        //die();
        $this->database_query = "UPDATE page_module SET module_name='".$variables['module_name']."', module_title='".$variables['module_title']."', module_keywords='".$variables['module_keywords']."', module_description='".$variables['module_description']."', module_access_level='".$variables['module_access_level']."' WHERE id=".$variables['module_id'].";";
    }
    
    /**
     * redirect_action()
     * redirect module list
     * 
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Moduleadmin_Data_Modulelistredirect;
        $this->redirect_action->main($variables);
    }

}
